package a66weding.com.jiehuntong.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.andview.refreshview.XRefreshView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.xutils.view.annotation.Event;

import java.util.List;

import a66weding.com.jiehuntong.R;
import a66weding.com.jiehuntong.adapter.AddFriends_2_Adpter;
import a66weding.com.jiehuntong.adapter.FriendListAdapter;
import a66weding.com.jiehuntong.beans.PersonBean;
import a66weding.com.jiehuntong.common.MessageEvent;
import a66weding.com.jiehuntong.inner.OnItemClickLitener;
import a66weding.com.jiehuntong.widgets.DividerItemDecoration;

/**
 * Created by admin on 2016/7/25.
 * 添加朋友
 */
public class AddFrinds_2_Actvitiy extends Activity implements OnItemClickLitener {
    private XRefreshView xRefreshView;
    private RecyclerView recyclerView;
    private AddFriends_2_Adpter adpter;
    List<PersonBean.DataBean> list;
    private PersonBean.DataBean bean;
    private TextView back_iamge;
    private TextView title_tv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_addfriends_2);
        EventBus.getDefault().register(this);
        list = (List<PersonBean.DataBean>) getIntent().getSerializableExtra(AddFriendsActivity.ADDFRIENDSACTIVITY);
        initView();
    }
    private void initView(){
        back_iamge = (TextView) findViewById(R.id.back_iamge);
        back_iamge.setText("添加朋友");
        title_tv = (TextView) findViewById(R.id.title_tv);
        title_tv.setText("添加朋友");
        initRefreshView();
    }
    //初始化上啦刷新
    private void initRefreshView() {
        xRefreshView = (XRefreshView)findViewById(R.id.add_xrefreshview);
        //是否允许下拉刷新
        xRefreshView.setPullRefreshEnable(false);
        // 设置是否可以上拉加载
        xRefreshView.setPullLoadEnable(true);
        // 设置刷新完成以后，headerview固定的时间
        xRefreshView.setPinnedTime(1000);
        // 静默加载模式不能设置footerview
        // 设置支持自动刷新
        xRefreshView.setAutoLoadMore(true);
        recyclerView = (RecyclerView)findViewById(R.id.add_recycler_view_test_rv);
        recyclerView.setHasFixedSize(true);
        //线性布局
        recyclerView.setLayoutManager(new LinearLayoutManager(this));

        adpter = new AddFriends_2_Adpter(this,list);
        adpter.setOnItemClickLitener(this);
        recyclerView.setAdapter(adpter);
        recyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL_LIST));
        xRefreshView.setXRefreshViewListener(new XRefreshView.SimpleXRefreshListener() {
            @Override
            public void onRefresh() {
                getNetData();

            }

            @Override
            public void onLoadMore(boolean isSlience) {
                getNetData();
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Override
    public void onItemClick(View view, int position) {
        bean = list.get(position);
        Intent intent = new Intent(this,PersonHomeActivity.class);
        intent.putExtra(AddFriendsActivity.ADDFRIENDSACTIVITY,bean);
        startActivity(intent);
        overridePendingTransition(R.anim.tween_enter, R.anim.tween_exit);
    }
    private void getNetData(){

    }
    //返回
    public void back(View view){
        finish();
    }

    @Subscribe
    public void onEvent(MessageEvent event) {
        event.getFinish();
        finish();
    }
}
